/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.liquidByte.trafficMustang.server.dataModel;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import javax.persistence.*;
import javax.validation.constraints.NotNull;

/**
 *
 * @author Alexandre
 */
@Entity
@Table(name = "rastr")
public class Rastreamento implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected RastreamentoPK rastreamentoPK;
    @Embedded
    @AttributeOverrides({
        @AttributeOverride(column=@Column(name="RASTR_LONG"),name="longitude"),
        @AttributeOverride(column=@Column(name="RASTR_LAT"),name="latitude")
    })
    private Localizacao localizacao;
    @JoinColumn(name = "USR_ID", referencedColumnName = "USR_ID", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Usuario usuario;

    public Rastreamento() {
    }

    public Rastreamento(RastreamentoPK rastreamentoPK) {
        this.rastreamentoPK = rastreamentoPK;
    }

    public Rastreamento(RastreamentoPK rastreamentoPK, Localizacao localizacao) {
        this.rastreamentoPK = rastreamentoPK;
        this.localizacao = localizacao;
    }

    public Rastreamento(int usrId, Date rastrDt) {
        this.rastreamentoPK = new RastreamentoPK(usrId, rastrDt);
    }

    public RastreamentoPK getRastreamentoPK() {
        return rastreamentoPK;
    }

    public void setRastreamentoPK(RastreamentoPK rastreamentoPK) {
        this.rastreamentoPK = rastreamentoPK;
    }

    public Localizacao getLocalizacao() {
        return localizacao;
    }

    public void setLocalizacao(Localizacao localizacao) {
        this.localizacao = localizacao;
    }
    
    public Usuario getUsuario() {
        return usuario;
    }

    public void setUsuario(Usuario usuario) {
        this.usuario = usuario;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (rastreamentoPK != null ? rastreamentoPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Rastreamento)) {
            return false;
        }
        Rastreamento other = (Rastreamento) object;
        if ((this.rastreamentoPK == null && other.rastreamentoPK != null) || (this.rastreamentoPK != null && !this.rastreamentoPK.equals(other.rastreamentoPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "org.liquidByte.trafficMustang.server.dataModel.Rastreamento[ rastreamentoPK=" + rastreamentoPK + " ]";
    }
    
}
